use model_graph_common::config::get_peer_config;
use serde::{Serialize, Serializer};
use std::{collections::HashMap, sync::Mutex};
use tauri::{command, AppHandle, Runtime, State, Window};

use data_transform::DefaultDataTransformer;
use serde_json::Value as JsonValue;
use std::path::PathBuf;
use union_connector::UnionConnector;

use super::ContextState;
use super::Error;
use super::Result;

use metadata_extractor::DefaultMetadataExtractor;
use model_graph_types::{
    database::{ConnectorProtocol, DataSource, DatabaseType},
    extractor::{ExtractFromDatabaseOption, MetadataExtractor, MetadataPackage},
    modeling::{Class, ModelingReader, ModelingWriter},
};

#[command]
pub async fn extractor_meta_from_database<R: Runtime>(
    _app: AppHandle<R>,
    _window: Window<R>,
    state: State<'_, ContextState>,
    data_source: DataSource,
    options: ExtractFromDatabaseOption,
) -> Result<MetadataPackage> {
    //
    let extractor = DefaultMetadataExtractor {};
    //
    let packages = extractor
        .extract_from_database(&data_source, ExtractFromDatabaseOption {})
        .await?;

    Ok(packages)
}
